package com.intelligent.system.auth.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.intelligent.system.auth.dto.PersonDTO;
import com.intelligent.system.auth.dto.PersonQueryDTO;
import com.intelligent.system.auth.service.PersonService;
import com.intelligent.system.common.response.ResultDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/api/persons")
@Api(tags = "人员管理接口")
public class PersonController {

    @Resource
    private PersonService personService;

    @PostMapping("/page")
    @ApiOperation("分页查询人员列表")
    public ResultDO<IPage<PersonDTO>> page(
            @ApiParam(value = "查询参数", required = true)
            @Validated @RequestBody PersonQueryDTO queryDTO) {
        return personService.page(queryDTO);
    }

    @ApiOperation("新增人员")
    @PostMapping("/add")
    public ResultDO<?> save(
            @ApiParam(value = "人员信息", required = true)
            @RequestBody PersonDTO personDTO) {
        return personService.save(personDTO);
    }

    @PostMapping("/update")
    @ApiOperation("更新人员")
    public ResultDO<?> update(
            @ApiParam(value = "人员信息", required = true)
            @RequestBody PersonDTO personDTO) {
        return personService.update(personDTO);
    }

    @GetMapping("/delete/{id}")
    @ApiOperation("删除人员")
    public ResultDO<?> removeById(
            @ApiParam(value = "人员ID", required = true)
            @PathVariable Long id) {
        return personService.removePersonById(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID获取人员")
    public ResultDO<PersonDTO> getById(
            @ApiParam(value = "人员ID", required = true)
            @PathVariable Long id) {
        return personService.getPersonById(id);
    }
}
